package com.caszx.chargingpile.holder.reservate;

import android.app.Activity;
import android.content.Intent;
import android.view.View;
import android.widget.TextView;

import com.app.base.adapter.holder.BaseHolder;
import com.caszx.chargingpile.R;
import com.caszx.chargingpile.activity.ReservatePayActivity;
import com.caszx.chargingpile.entity.EntitySubRecord;
import com.caszx.chargingpile.user.LocationManager;

import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.Date;

import de.greenrobot.event.EventBus;

/**
 * 预约记录
 */
public class ReservateIngHolder extends BaseHolder<EntitySubRecord> implements View.OnClickListener{


    private TextView txtTitle;
    private TextView txtDistance;
    private TextView txtNumber;
    private TextView txtPayStatus;
    private TextView txtInfo;
    private TextView btn_reservate;
    private TextView btn_delete;

    private static DecimalFormat decimalFormat = new DecimalFormat("###.##");
    private static SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm");
    public ReservateIngHolder(View view) {
        super(view);
    }

    @Override
    protected void initView() {

        txtTitle = (TextView) mRootView.findViewById(R.id.txtTitle);
        txtDistance = (TextView) mRootView.findViewById(R.id.txtDistance);
        txtNumber = (TextView) mRootView.findViewById(R.id.txtNumber);
        txtPayStatus = (TextView) mRootView.findViewById(R.id.txtPayStatus);
        txtInfo = (TextView) mRootView.findViewById(R.id.txtInfo);
        btn_reservate = (TextView) mRootView.findViewById(R.id.btn_reservate);
        btn_delete = (TextView) mRootView.findViewById(R.id.btn_delete);
        btn_reservate.setOnClickListener(this);
        btn_delete.setOnClickListener(this);

    }

    @Override
    protected void refreshView() {
        txtTitle.setText(mItem.stationName);
        txtDistance.setText(decimalFormat.format(mItem.distence/1000)+"km");
        txtNumber.setText("编号:"+mItem.pileNo);
        txtPayStatus.setText("消费金额 ￥"+decimalFormat.format(mItem.totalBeforeFee)+"   "+mItem.subscribeStatus);
        txtInfo.setText("预约时间  "+dateFormat.format(new Date(mItem.startDate))+"  至  "+dateFormat.format(new Date(mItem.endDate)));
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.btn_reservate:
                EventBus.getDefault().post(mItem);
                break;
            //再次预约
            case R.id.btn_delete:
                Intent intent = new Intent(mRootView.getContext(),ReservatePayActivity.class);
                intent.putExtra("ID",mItem.stationId);
                intent.putExtra("NAME",mItem.stationName);
                mRootView.getContext().startActivity(intent);
                break;
        }
    }
}
